<template>
	<view class="share-page">
		<view class="">
			<u-tag :text="'推广数：'+countData.total"></u-tag>
			<u-tag :text="'推广有效数：'+countData.available" type="success"></u-tag>
		</view>
		<zTable :tableData="tableData.data" textAlign="center" titleTextAlign="center" :columns="tableColumns"
			:showLoading="tableData.data.length !=0" emptyText="暂无数据"></zTable>
		<view v-if="tableData.total>0">
			<lsitPage :totalNum="tableData.total" pageCount="10" :curPageNum="tableData.page" @pageClick="pageClick">
			</lsitPage>
		</view>
	</view>
</template>

<script setup lang="ts">
	import { nextTick, reactive, ref } from "vue";
	import { onLoad, onShow, onShareAppMessage } from "@dcloudio/uni-app";
	import { getShare, getShareCount } from "@/utils/api";
	import zTable from '@/components/z-table/z-table.vue'
	import lsitPage from '@/components/cc-listPageView/cc-listPageView.vue'
	const tableData = reactive({
		data: [],
		page: 1,
		size: 10,
		total: 0
	})
	const tableColumns = ref([
		{
			title: '#',
			key: 'index',
			width: 50
		},
		{
			title: '手机号',
			key: 'memberPhone',
			width: 250,
			formatNum: false
		},
		{
			title: '是否已结算',
			key: 'clearedData',
			width: 180,
		},
		{
			title: '分享时间',
			key: 'createTime',
			width: 266
		},
	])
	const countData = reactive({
		total: 0,
		available: 0
	})
	function getTableData() {
		const params = {
			current: tableData.page,
			size: tableData.size
		}
		getShare(params).then((res : any) => {
			if (res.code == 200) {
				tableData.data = res.data.records;
				tableData.data.forEach((item : any, index) => {
					item.index = index + 1;
					if (item.cleared) {
						item.clearedData = '是'
					} else {
						item.clearedData = '否'
					}
				})
				tableData.total = res.data.total;
			}
		})
	}
	function pageClick(tag) {
		if (tag === 0) {
			// 上一页 (不等于第一页)
			if (tableData.page > 1) {
				tableData.page--;
				getTableData();
			}
		} else {
			// 下一页 (不等于最后一页)
			if (tableData.total > (tableData.page * 10)) {
				tableData.page++;
				getTableData();
			}

		}

	}
	function getCount() {
		getShareCount().then((res : any) => {
			if (res.code == 200) {
				countData.available = res.data.available;
				countData.total = res.data.total;
			}
		})
	}
	onLoad(() => {
		getTableData();
		getCount();
	})
</script>

<style lang="scss">

</style>